package com.huawei.appmarket.framework.widget;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.LayerDrawable;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.style.ImageSpan;
import android.text.style.ReplacementSpan;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.TextView;
import androidx.annotation.Nullable;
import com.huawei.appgallery.foundation.ui.css.CSSRule;
import com.huawei.appgallery.foundation.ui.css.CSSViewProxy;
import com.huawei.appgallery.foundation.ui.css.RenderListener;
import com.huawei.appgallery.foundation.ui.css.adapter.CSSPropertyName;
import com.huawei.appgallery.foundation.ui.css.adapter.type.CSSMonoColor;
import com.huawei.appgallery.foundation.ui.css.adapter.type.CSSValue;
import com.huawei.hwid.core.constants.HwAccountConstants;
import huawei.widget.HwTextView;
import o.erq;
import o.evf;
import o.ewm.c;
import o.ewm.e;
import o.ewm.h;
import o.ewm.j;

public class TagRenderTextView extends HwTextView implements RenderListener {
    private TextView ˋ;

    public TagRenderTextView(Context context) {
        this(context, null);
    }

    public TagRenderTextView(Context context, @Nullable AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    public TagRenderTextView(Context context, @Nullable AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
    }

    private void ˊ() {
        this.ˋ = (TextView) LayoutInflater.from(getContext()).inflate(h.ˈᐝ, null).findViewById(j.ʿˉ);
        evf.ˎ(this.ˋ, e.ᶥ);
        evf.ˋ(this.ˋ, c.ॱˊ);
    }

    public void setTagStyle(int i, Drawable drawable) {
        if (this.ˋ != null) {
            this.ˋ.setTextColor(i);
            this.ˋ.setBackground(drawable);
        }
    }

    public void setData(String str, String str2, int i) {
        if (TextUtils.isEmpty(str2)) {
            setText(str);
            return;
        }
        if (this.ˋ == null) {
            ˊ();
        }
        this.ˋ.setText(str2);
        CharSequence spannableStringBuilder = new SpannableStringBuilder();
        spannableStringBuilder.append(ˎ(new c(this.ˋ)));
        Drawable colorDrawable = new ColorDrawable(0);
        colorDrawable.setBounds(0, 0, i, 0);
        spannableStringBuilder.append(ˎ(new ImageSpan(colorDrawable)));
        spannableStringBuilder.append(str);
        setText(spannableStringBuilder);
        setContentDescription(str2 + HwAccountConstants.BLANK + str);
    }

    private SpannableString ˎ(ReplacementSpan replacementSpan) {
        SpannableString spannableString = new SpannableString("TAG");
        spannableString.setSpan(replacementSpan, 0, "TAG".length(), 17);
        return spannableString;
    }

    public boolean onRenderReady(CSSViewProxy cSSViewProxy) {
        CSSRule rule = cSSViewProxy.getRule();
        if (rule.getStyleDeclaration() == null) {
            return false;
        }
        CSSValue propertyValue = rule.getStyleDeclaration().getPropertyValue(CSSPropertyName.FONT_COLOR);
        if (!(propertyValue instanceof CSSMonoColor)) {
            return false;
        }
        int color = ((CSSMonoColor) propertyValue).getColor();
        setTagStyle(color, ॱ(getContext(), erq.ˊ(color, 0.5f)));
        return true;
    }

    private Drawable ॱ(Context context, int i) {
        GradientDrawable gradientDrawable = (GradientDrawable) ((LayerDrawable) context.getResources().getDrawable(e.ᶥ)).findDrawableByLayerId(16908288);
        if (gradientDrawable == null) {
            return null;
        }
        gradientDrawable.setStroke(2, i);
        return gradientDrawable;
    }
}
